<?php

namespace app\admin\service\channel;

use tmcore\base\BaseService;
use app\common\model\setting\Config as ConfigModel;
use tmcore\services\ConfigService;

class H5Service extends BaseService
{
    /**
     * 获取H5渠道信息
     * @return array
     */
    public static function getH5Config(): array
    {
        $config = com_get_config( 'h5_channel','sys');
        return [
            'status' => $config['status'] ?? 1,
            'url' => request()->domain() . '/app',
            'close_url' => $config['close_url'] ?? '',
        ];
    }

    /**
     * 设置H5渠道信息
     * @param array $params
     * @return bool
     */
    public static function setH5Config(array $params)
    {
        $data = [
            'status' => isset($params['status'])?intval($params['status']):'', // 渠道状态
            'close_url' => $params['close_url']??'', // 关闭后访问地址
        ];

        $res = ConfigModel::where(['name' => 'h5_channel'])->update(['value' => json_encode($data, 320)]);

        (new ConfigService)->setConfig('create', 'sys', 'h5_channel');

        return $res !== false;
    }
}